osType = os.getenv("OS")
local cmd = "rm -f "..globalLuaPath.."/ttbuild_native.lua "

local platformBuildScript = ""
if osType and "Windows_NT" == osType then
	platformBuildScript = globalLuaPath.."/ttbuild_mingw32.lua "
else
	platformBuildScript = globalLuaPath.."/ttbuild_linux.lua "
end

local nativeBuildScript= ""
local platform = assert(io.open(platformBuildScript, "r"))
for line in platform:lines() do 
	nativeBuildScript = nativeBuildScript..line.."\n"
end
platform:close()

local ttcodeNative = assert(io.open(globalLuaPath.."/ttbuild_native.lua ","w+"))
ttcodeNative:write(nativeBuildScript)
ttcodeNative:close()


local cmakeConfig = ""
cmakeConfig = cmakeConfig.."FIND_PROGRAM(CMAKE_MAKE_PROGRAM\n"
cmakeConfig = cmakeConfig.."  NAMES ttbuild\n"
cmakeConfig = cmakeConfig.."  PATHS\n"
cmakeConfig = cmakeConfig.."  "..globalTTHome.."/tt-app/bin\n"
cmakeConfig = cmakeConfig.."  )\n"
cmakeConfig = cmakeConfig.."MARK_AS_ADVANCED(CMAKE_MAKE_PROGRAM)\n"

cmakeConfig = cmakeConfig.."FIND_PROGRAM(CMAKE_GENERATOR_CC\n"
cmakeConfig = cmakeConfig.."  NAMES ttcc\n"
cmakeConfig = cmakeConfig.."  PATHS\n"
cmakeConfig = cmakeConfig.."  "..globalTTHome.."/tt-app/bin\n"
cmakeConfig = cmakeConfig.."  )\n"
cmakeConfig = cmakeConfig.."MARK_AS_ADVANCED(CMAKE_GENERATOR_CC)\n"

cmakeConfig = cmakeConfig.."FIND_PROGRAM(CMAKE_GENERATOR_CXX\n"
cmakeConfig = cmakeConfig.."  NAMES ttcc++\n"
cmakeConfig = cmakeConfig.."  PATHS\n"
cmakeConfig = cmakeConfig.."  "..globalTTHome.."/tt-app/bin\n"
cmakeConfig = cmakeConfig.."  )\n"
cmakeConfig = cmakeConfig.."MARK_AS_ADVANCED(CMAKE_GENERATOR_CXX)\n"

local ttcodeModule = assert(io.open(globalTTHome.."/import-app/cmake/share/cmake-2.8/Modules/CMakeFindTTCode.cmake","w+"))
ttcodeModule:write(cmakeConfig)
ttcodeModule:close()
